//
//  AppDelegate.swift
//  XMYouPin
//
//  Created by 王宗成 on 2019/7/2.
//  Copyright © 2019 王宗成. All rights reserved.
//

import UIKit
import CYLTabBarController
import HandyJSON
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
    
    var window: UIWindow?
    lazy var tabBarController : CYLTabBarController = {
   
        
        var home:HomeViewController = HomeViewController();
        var homeNav:WZC_NavigationController = WZC_NavigationController(rootViewController: home)
        
        var classs:ClassViewController = ClassViewController();
        var classsNav:WZC_NavigationController = WZC_NavigationController(rootViewController: classs)
        
        var pin:PinViewController = PinViewController();
        var pinNav:WZC_NavigationController = WZC_NavigationController(rootViewController: pin)
        
        var shopCar:ShopCarViewController = ShopCarViewController();
        var shopCarNav:WZC_NavigationController = WZC_NavigationController(rootViewController: shopCar)
        
        var personVC:MyViewController = MyViewController();
        var personNav:WZC_NavigationController = WZC_NavigationController(rootViewController: personVC)
        
        var attributesDic1:[String:String] = [CYLTabBarItemTitle : "首页",
                                              CYLTabBarItemImage : "mjyp_tabbar_icon_0",
                                              CYLTabBarItemSelectedImage : "mjyp_tabbar_icon_0_selected"]
        
        var attributesDic2:[String:String] = [CYLTabBarItemTitle :"分类",
                                              CYLTabBarItemImage : "mjyp_tabbar_icon_1",
                                              CYLTabBarItemSelectedImage : "mjyp_tabbar_icon_1_selected"]
        
        var attributesDic3:[String:String] = [CYLTabBarItemTitle : "品味",
                                              CYLTabBarItemImage : "mjyp_tabbar_icon_2",
                                              CYLTabBarItemSelectedImage : "mjyp_tabbar_icon_2_selected"]
        
        var attributesDic4:[String:String] = [CYLTabBarItemTitle : "购物车",
                                              CYLTabBarItemImage : "mjyp_tabbar_icon_3",
                                              CYLTabBarItemSelectedImage : "mjyp_tabbar_icon_3_selected"]
        
        var attributesDic5:[String:String] = [CYLTabBarItemTitle : "个人",
                                              CYLTabBarItemImage : "mjyp_tabbar_icon_4",
                                              CYLTabBarItemSelectedImage : "mjyp_tabbar_icon_4_selected"]
     
        var tabBarVC:CYLTabBarController = CYLTabBarController(viewControllers: [homeNav,classsNav,pinNav,shopCarNav,personNav], tabBarItemsAttributes: [attributesDic1,attributesDic2,attributesDic3,attributesDic4,attributesDic5])
        
        return tabBarVC
    }()
    
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // 1.加载tabbar样式
        self.window = UIWindow(frame: CGRect(x: 0, y: 0, width: kScreenW, height:kScreenH ))
        self.window?.backgroundColor = UIColor.white
        self.window?.rootViewController = self.tabBarController
        self.window?.makeKeyAndVisible()

        customizeInterface()
        
        return true
    }
    
    //导航栏设置
    func setNavBarAppearence() -> Void {
        
        // 设置导航栏默认的背景颜色
        WRNavigationBar.defaultNavBarBarTintColor = UIColor.hexColor(hexadecimal: kNavBarBgColor)
        // 设置导航栏所有按钮的默认颜色
        WRNavigationBar.defaultNavBarTintColor = .white
        // 设置导航栏标题默认颜色
        WRNavigationBar.defaultNavBarTitleColor = .white
        // 统一设置状态栏样式
        WRNavigationBar.defaultStatusBarStyle = .default
        // 如果需要设置导航栏底部分割线隐藏，可以在这里统一设置
        WRNavigationBar.defaultShadowImageHidden = true
        
    }
    
    //底部标签栏
    func customizeInterface() -> Void {
        
        // 普通状态下的文字属性
        let normalAttrs = [NSAttributedString.Key.foregroundColor:UIColor.hexColor(hexadecimal: "#865B2E")]
        // 选中状态下的文字属性865B2E
        let selectedAttrs = [NSAttributedString.Key.foregroundColor:UIColor.hexColor(hexadecimal: "#865B2E")]
        
        let tabBar = UITabBarItem.appearance()
        
        tabBar.setTitleTextAttributes(normalAttrs, for: UIControl.State.normal)
        
        tabBar.setTitleTextAttributes(selectedAttrs, for: UIControl.State.selected)
        
    }
    
}
